<html><head></head>
<body background="../img/noa.jpg">
<?php
$cod=$_POST['fcodpac'];
$con= mysql_connect('localhost','root','');
mysql_select_db('spa_medico');
$conUsu = mysql_query("select * from (select * from contrata where cod_paciente = '$cod') c left join (select p.cod_paciente, e.nombre, e.ap_paterno, e.ap_materno from paciente p left join persona e on p.cod_persona = e.cod_persona) w on c.cod_paciente = w.cod_paciente left join tratamiento t on c.cod_tratamiento = t.cod_tratamiento left join trata_precio tp on c.cod_tratamiento = tp.cod_trata where c.num_cesiones = tp.num_cesiones");
?>
<h1 align="center"><?php echo("Registro Paciente : ".$cod); ?></h1>
<form name="formulario" action="cambia_reserva.php" method="post">
<table width="960" border="1" align="center" bgcolor="#95A2D5">
<tr ><td><h3 align="center"> Num. Registro </h3></td><td><h3 align="center"> Paciente </h3></td><td><h3 align="center"> Tratamiento </h3></td><td><h3 align="center"> Fecha del registro </h3></td><td><h3 align="center"> Num. Cesiones </h3></td><td><h3 align="center"> Monto </h3></td><td><h3 align="center"> Canselado </h3></td><td><h3 align="center"> Saldo </h3></td></tr>
<?php 
while ($resUsu = mysql_fetch_array($conUsu)){
		echo ("<tr><td>".$resUsu['cod_contrata']."</td>");
		echo ("<td>".$resUsu['nombre']." ".$resUsu['ap_paterno']." ".$resUsu['ap_materno']."</td>");
		echo ("<td>".$resUsu['desctrata']."</td>");
		echo ("<td>".$resUsu['fecha']."</td>");
		echo ("<td>".$resUsu['num_cesiones']."</td>");
		echo ("<td> bs. ".$resUsu['precio']."</td>");
		$conpa = mysql_query("select cod_contrata, sum(monto) pagos from pagos where cod_contrata = '$resUsu[cod_contrata]' group by cod_contrata");
		$respa = mysql_fetch_array($conpa);
		echo ("<td> bs. ".$respa['pagos']."</td>");
		if($resUsu['precio']>$respa['pagos'])
		{
			echo ("<td> bs.".($resUsu['precio']-$respa['pagos'])." </td>");
		}
		else
		{
			echo ("<td> Total Canselado </td>");
		}
}
?>
</table>
<?php 
@@mysql_free_result($conUsu);
@@mysql_close($conexion);
?>
</body>
</html>